package com.zrh.jsd.common.exception;

import com.zrh.jsd.common.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public Result handlerCommonException (Exception e) {
        Result result = new Result<>();
        result.setCode(ResponseCodeEnum.FAILURE.getCode());
        result.setMessage(ResponseCodeEnum.FAILURE.getMessage());
        log.info("UnifyExceptionHandler.handlerCommonException exception:" + e);
        return result;
    }
    // 执行范围最接近的异常
    @ExceptionHandler(ArithmeticException.class)
    public Result handlerArithmeticException (Exception e) {
        Result result = new Result<>();
        result.setCode(ResponseCodeEnum.FAILURE.getCode());
        result.setMessage(ResponseCodeEnum.FAILURE.getMessage());
        log.info("UnifyExceptionHandler.handlerArithmeticException exception:" + e);
        return result;
    }

}
